<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    

<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<link rel="stylesheet" type="text/css" href="css/maintable.css"></link>

</head>
	<script >
		$(function(){
			//页面加载完，给传入的roleId添加checked属性，显示选择的用户的角色
			check(${roleId});
			//点击单选框时，将单选的checked属性移除，给点击到的添加
			$("input[name=role]").click(function(){
				$("input[name=role]").removeAttr("checked");
				$(this).attr("checked","checked");
			});
		});
		
		//给单选添加checked属性
		function check(e){
			$("input[value="+e+"]").attr("checked","checked");
		}
	</script>
	<script >
		function tijiao(){
			var ok=confirm("确认提交吗");
			if(ok==false){
				return ok;
			}else{
				$.ajax({
					type:"POST",
					url:"RoleServlet.do",
					data:{flog:"changeAdminRole",roleId:$("input[checked]").val(),adminName:$("input[name=adminName]").val()},
					async:false,
					success:function(o){
						check(o);
						alert("用户角色更新成功！");
					}
				});
			}
			
		}
	</script>

<body>
	<div class="div_title">
		<div class="div_titlename">
			<img src="images/san_jiao.gif"><span>管理员添加</span>
		</div>
	</div>
	
	<table class="main_table">
		<tr>
			<td>用户账号</td>
			<td>
				
				<input value="${roleAdminName}" name="adminName">
			</td>
		</tr>
		<tr>
			<td>用户角色</td>
			<td>
				<c:forEach var="role" items="${roleList}" >
					<input type="radio" id="${role.id}" value="${role.id}" name="role" >${role.roleName }<br/>
				</c:forEach>
			</td>
		</tr>
		
		<tr>
			<td>
				<a  onclick="return tijiao()">提交</a>
			</td>
			<td>
				<a href="RoleServlet.do?flog=listadmin">返回</a>
			</td>
		</tr>
	</table>
</body>
</html>	
